const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');

//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    TabCur: 0,
    catalog: {},
    img: [],
    goods: [],

    load: true
  },
  getguanggao() {
    let that = this
    util.request(api.QueryAdvert, {

    }).then(function(res) {
      console.log('111' + res)
      that.setData({
        img: res.data.noticeList
      });
    });
  },
  onLoad() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    this.getcatalog()
    this.getguanggao()
  },
  onReady() {
    wx.hideLoading()
  },
  tabSelect(e) {
    console.log(e)
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      MainCur: e.currentTarget.dataset.id,
      VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
    })
    this.getgoods()
  },
  getcatalog() {
    let that = this
    util.request(api.Catalog, {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
      'X-Qxmall-Token': wx.getStorageSync('token')
    }).then(function(res) {
      console.log(res)
      that.setData({
        catalog: res.data.parentSort,
        TabCur: res.data.parentSort[0].id
      })
      that.getgoods()
    });
  },
  getgoods() {
    let that = this
    util.request(api.QuerySortGoods, {
      sortId: that.data.TabCur
    }, 'get', {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
      'X-Qxmall-Token': wx.getStorageSync('token')
    }).then(function(res) {
      console.log(res)
      that.setData({
        goods: res.data.querySortGoods
      })
    });
  },
 
  onShow: function() {
    this.getgoods()
  }
})